package Salesman.gui;

import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import org.jdesktop.swingx.JXMapKit;
import org.jdesktop.swingx.JXMapViewer;
import org.jdesktop.swingx.mapviewer.GeoPosition;
import org.jdesktop.swingx.painter.Painter;


public class MapKit extends JXMapKit {

    private GeoPosition lastPos;
    
    public MapKit() {
        
        setDefaultProvider(DefaultProviders.OpenStreetMaps);
        setDataProviderCreditShown(true);
        setMiniMapVisible(false);
        setZoomSliderVisible(false);

        getMainMap().setOverlayPainter(null);
        setZoom(10);

        getMainMap().addMouseMotionListener(new MouseMotionListener() {

            @Override
            public void mouseDragged(MouseEvent e) {
            }

            @Override
            public void mouseMoved(MouseEvent e) {
                lastPos = getMainMap().convertPointToGeoPosition(e.getPoint());
            }
        });


        getMainMap().addMouseWheelListener(new MouseWheelListener() {

            @Override
            public void mouseWheelMoved(MouseWheelEvent e) {

                GeoPosition nowPos = getMainMap().convertPointToGeoPosition(e.getPoint());

                double dLat = nowPos.getLatitude() - lastPos.getLatitude();
                double dLon = nowPos.getLongitude() - lastPos.getLongitude();

                GeoPosition newPos = new GeoPosition(getMainMap().getCenterPosition().getLatitude() - dLat, getMainMap().getCenterPosition().getLongitude() - dLon);

                setAddressLocation(newPos);
            }
        });
    }
    
      
}
